package open.intellijboy.core.spring.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 应用启动监听器 - 监听应用启动完成事件
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
@Slf4j
@Component
public class ApplicationStartupListener implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        Environment env = event.getApplicationContext().getEnvironment();
        String serverPort = env.getProperty("server.port", "8080");
        String contextPath = env.getProperty("server.servlet.context-path", "");

        log.info("=".repeat(80));
        log.info("🎉 旅游景区门票预约系统启动成功！");
        log.info("📱 应用访问地址: http://localhost:{}{}", serverPort, contextPath);
        log.info("📚 API文档地址: http://localhost:{}{}/swagger-ui/index.html", serverPort, contextPath);
        log.info("🔍 H2数据库控制台: http://localhost:{}{}/h2-console", serverPort, contextPath);
        log.info("🏠 默认首页: http://localhost:{}{}/", serverPort, contextPath);
        log.info("=".repeat(80));
    }
}

